package com.cy.web.controller;

import com.cy.pojo.Notice;
import com.cy.service.NoticeService;
import com.cy.web.common.util.PageHelperUtil;
import com.cy.web.pojo.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@ResponseBody
@RequestMapping("/notice")
public class NoticeController {

    @Autowired
    private NoticeService noticeService;

    @GetMapping("/doGetNotices")
    public JsonResult doGetNotices(@RequestBody Notice notice){
        return new JsonResult(
                PageHelperUtil.startPage().doSelectPageInfo(
                        ()->noticeService.getNotices(notice)));
    }

    @GetMapping("/doGetNotice/{id}")
    public JsonResult doGetNotice(@PathVariable Long id){
        return new JsonResult(noticeService.getNoticeById(id));
    }

    @PostMapping("/doSaveNotice")
    public JsonResult doSaveNotice(@RequestBody Notice notice){
        int i = noticeService.saveNotice(notice);
        return new JsonResult("save ok");
    }

    @PutMapping("/doUpdateNotice")
    public JsonResult doUpdateNotice(@RequestBody Notice notice){
        return new JsonResult(noticeService.updateNotice(notice));
    }

    @DeleteMapping("/doDeleteNotice/{ids}")
    public JsonResult doDeleteNotice(@PathVariable Long... ids){
        return new JsonResult(noticeService.deleteNotices(ids));
    }

    @DeleteMapping("/doDeleteNoticeById/{id}")
    public JsonResult doDeleteNoticeById(@PathVariable Long id){
        return new JsonResult(noticeService.deleteNotice(id));
    }
}
